﻿Public Class FrmPerson

    Private x_council As X_Council
    Private x_person As X_Person
    Private x_person_old As X_Person
    Private _parentForm As SuperForm

    Public Sub New(ByVal xcouncil As X_Council, ByVal xperson As X_Person, ByVal parentForm As SuperForm)
        InitializeComponent()

        Me._parentForm = parentForm

        Me.x_council = xcouncil

        Me.x_person = xperson
        If (Not Me.x_council Is Nothing) Then
            Me.x_person.setValue(I_Person.ColumnName_CouncilID, Me.x_council.getValue(I_Council.ColumnName_id))
        End If

        Me.x_person_old = Me.x_person
        ini()
    End Sub

    Private Function ini() As Boolean
        Me.txtHoTen.Text = Me.x_person_old.getValue(I_Person.ColumnName_HoTen)
        Me.txtChucVu.Text = Me.x_person_old.getValue(I_Person.ColumnName_ChucVu)
        Me.txtDaiDien.Text = Me.x_person_old.getValue(I_Person.ColumnName_DaiDien)
        Me.txtDienGiai.Text = Me.x_person_old.getValue(I_Person.ColumnName_DienGiai)
        Return True
    End Function


    Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub


    Private Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click
        ini()
    End Sub


    Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click

        Me.x_person.setValue(I_Person.ColumnName_ChucVu, Me.txtChucVu.Text)
        Me.x_person.setValue(I_Person.ColumnName_DaiDien, Me.txtDaiDien.Text)
        Me.x_person.setValue(I_Person.ColumnName_DienGiai, Me.txtDienGiai.Text)
        Me.x_person.setValue(I_Person.ColumnName_HoTen, Me.txtHoTen.Text)
        Me.x_person.save(True)

        Me._parentForm.loadDetail()
        Me.Close()

    End Sub
End Class